package ua.edu.test.adapter;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

import java.util.ArrayList;

/**
 * Created by Max on 11.07.2014.
 */
public class TabsPagerAdapter extends FragmentPagerAdapter{

	private static final String LOG_TAG = TabsPagerAdapter.class.getName();

	private FragmentManager fm;
	private ArrayList<Fragment> pageItemsArrayList;


	public TabsPagerAdapter(FragmentManager fm, ArrayList<Fragment> pageItems) {
		super(fm);
		this.fm	= fm;
		this.pageItemsArrayList = pageItems;
	}

	public void setPagerItem(ArrayList<Fragment> pageItems, int tabNumber){
		if (pageItemsArrayList != null){
			fm.beginTransaction().remove( pageItemsArrayList.get(tabNumber) ).commit();
		}
		pageItemsArrayList = pageItems;
	}

	public void setPagerAllItems(ArrayList<Fragment> pageItems){

			if (pageItemsArrayList != null){

				for (int i = 0; i < pageItemsArrayList.size(); i++)

					fm.beginTransaction().remove( pageItemsArrayList.get(i) ).commit();
			}

		pageItemsArrayList = pageItems;
	}


//	Actions actionsFragment = new Actions();
//	MyCards myCardsFragment = new MyCards();


	@Override
	public Fragment getItem(int index) {
		if (index == 0){
			return pageItemsArrayList.get(0);
		}else if (index == 1){
			return pageItemsArrayList.get(1);
		}
		return null;
	}

	@Override
	public int getCount() {
//		return getItemId();
		return 2;
	}




}
